import 'package:bigegg/global/routes/xmm_routes.dart';
import 'package:bigegg/widget/xmm_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../../widget/image/xmm_circle_cached_network_image.dart';
import 'xmm_follow_controller.dart';

class XmmFollowPage extends StatefulWidget {
  const XmmFollowPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return XmmFollowPageState();
  }
}

class XmmFollowPageState extends State<XmmFollowPage>
    with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  @override
  bool get wantKeepAlive => true;

  XmmFollowController controller = Get.find<XmmFollowController>();

  @override
  void initState() {
    super.initState();
    controller.getFollowList();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
      children: [
        Flexible(
          child: Obx(
            () => controller.followList.isNotEmpty
                ? ListView.builder(
                    itemCount: controller.followList.length,
                    padding: const EdgeInsets.only(bottom: 100),
                    itemBuilder: (context, index) {
                      var item = controller.followList.elementAt(index);
                      return GestureDetector(
                        onTap: () => Get.toNamed(XmmRoutes.personPage,
                            arguments: item.userId),
                        child: Container(
                          alignment: Alignment.center,
                          height: 76.w,
                          padding: const EdgeInsets.only(
                            left: 20,
                            right: 20,
                            top: 16,
                            bottom: 16,
                          ),
                          child: Row(
                            children: [
                              XmmCircleCachedNetworkImage(
                                imageUrl: item.avatarUrl ?? "",
                                height: 44.w,
                                width: 44.w,
                              ),
                              const SizedBox(width: 10),
                              Expanded(
                                child: Text(
                                  item.nickname ?? "",
                                  style: TextStyle(
                                    fontSize: 14.sp,
                                    color: const Color(0xFF202020),
                                  ),
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                              GestureDetector(
                                child: Container(
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                      color: const Color(0xFF454545),
                                      borderRadius: BorderRadius.circular(37)),
                                  height: 26.w,
                                  width: 71.w,
                                  child: Text(
                                    "Unfollow",
                                    style: TextStyle(
                                      fontSize: 12.sp,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                onTap: () => controller.unfollow(item),
                              )
                            ],
                          ),
                        ),
                      );
                    },
                  )
                : getEmptyWidget(),
          ),
        ),
      ],
    );
  }
}
